package com.trkj.controllers;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.PayTable;
import com.trkj.pojos.TallydetailsTable;
import com.trkj.service.LiveInService;
import com.trkj.service.TallyService;
import com.trkj.vo.Info;
import com.trkj.vo.PayVo;
import com.trkj.vo.TallyTableVo;

@Controller
public final class HospitalTallyController {
	@Autowired
	private TallyService tallyService;
	@Autowired
	private LiveInService liveInService;
	/**
	 * 跳转记账界面
	 * @return
	 */
	@RequestMapping("/to_hspt_live_tally")
	public String to_hspt_live_tally( ){
		return "hspt_live_tally";
		
	}
	/**
	 * 跳转收费项目窗口
	 * @return
	 */
	@RequestMapping("/to_hspt_live_chargeProject")
	public String to_hspt_live_chargeProject( ){
		return "hspt_live_chargeProject";
		
	}
	/**
	 * 收费项目类型树
	 * @return
	 */
	@RequestMapping("/to_chargeTypeTree")
	@ResponseBody
	public List<Map<String,Object>> chargeTypeTree(){
		return tallyService.queryAllchargeTypeTotree();
	}
	/**
	 * 动态查询收费项目BY  ID
	 * @param page
	 * @param row
	 * @param typeID
	 * @return
	 */
	@RequestMapping("/to_querychargeByID")
	@ResponseBody
	public Map<String,Object> fuzzyquerycharge(int page,int rows,Long typeID){
		return tallyService.queryChargeProjectByTypeID(page, rows, typeID);
	}
	/**
	 * 动态查询收费项目BY  name
	 * @param page
	 * @param row
	 * @param name
	 * @return
	 */
	@RequestMapping("/to_querychargeByName")
	@ResponseBody
	public Map<String,Object> fuzzyquerychargeByname(int page,int rows,String name){
		return tallyService.queryChargeProjectByName(page, rows, name);
	}
	/**
	 * 创建账单号
	 * @return
	 */
	@RequestMapping("/to_createTallyID")
	@ResponseBody
	public String createTallyID(){
		return tallyService.CreateTallyID();
	}
	/**
	 * 跳转住院查询界面
	 */
	@RequestMapping("/to_queryPatientByLike_forTally")
	public String to_queryPatientByLike_forTally(){
		return "hspt_livepatient_quary";
	}
	/**
	 * 模糊查询病人byname
	 */
	@RequestMapping("/to_queryPatientByLikeNameForTally")
	@ResponseBody
	public Map<String,Object> queryPatientByLikeName(String likeName,int page,int rows){
		return liveInService.fuzzyQueryLiveInByname(likeName, page, rows);
		
	}
	/**
	 * 模糊查询病人byLiveID
	 */
	@RequestMapping("/to_queryPatientByLikeIDForTally")
	@ResponseBody
	public Map<String,Object> queryPatientByLikID(String likeID,int page,int rows){
		return liveInService.fuzzyQueryLiveInByLiveID(likeID, page, rows);
		
	}
	/**
	 * 添加每日记账账单
	 * @param tallyTableVo
	 */
	@RequestMapping("/to_addTally")
	public void addTally(TallyTableVo tallyTableVo){
		tallyService.addTally(tallyTableVo);
	}
	/**
	 * 查询账单未结费用   押金  余额  全部费用  已结算费用
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_queryBalance")
	@ResponseBody
	public Map<String,Object> queryBalance(String liveID){
		return tallyService.queryTallyBalance(liveID);
		
	}
	/**
	 * 查询全部未结算账单
	 * @return
	 */
	@RequestMapping("/to_queryNoAcountTally")
	@ResponseBody
	public List<Map<String,Object>> queryNoAcountTally(){
		return tallyService.queryNoAcountTally();
	}
	/**
	 * 查询个人未结账账单
	 * @return
	 */
	@RequestMapping("/to_queryNoAcountTallyByLiveID")
	@ResponseBody
	public Map<String, Object> queryNoAcountTallyByLiveID(int page,int rows,String liveID){
		return tallyService.queryNoAccountTallyByLiveID(page, rows, liveID);
	}
	/**
	 * 跳转账单详情核算界面
	 */
	@RequestMapping("/to_TallyDetialAccountW")
	public String TallyDetialAccountW(){
		return "hspt_live_tallyDetial";
	}
	/**
	 * 根据账单号查询未核算详情
	 * @param tallyID
	 * @return
	 */
	@RequestMapping("/to_queryTallyDetialToAccount")
	@ResponseBody
	public List<TallydetailsTable>  queryTallyDetialToAccount(String tallyID){
		return tallyService.queryAllNoAccountTallydetailsByTallyID(tallyID);
	}
	/**
	 * 根据账单号查询详情
	 * @param tallyID
	 * @return
	 */
	@RequestMapping("/to_queryTallyDetialToPay")
	@ResponseBody
	public List<TallydetailsTable>  queryTallyDetialToPay(String tallyID){
		return tallyService.queryAllTallydetailsByTallyID(tallyID);
	}
	/**
	 * 删除账单详情
	 * @param TallyID
	 * @param TallyDetailID
	 */
	@RequestMapping("/to_deleteTallyDetialfromAccount")
	@ResponseBody
	public Info  deleteTallyDetialfromAccount(String TallyDetailID,BigDecimal deleteSum){
		 boolean flag = tallyService.deleteTallyDetail(TallyDetailID,deleteSum);
	     return flag ? new Info() : new Info("删除失败！");
	}
	
	/**
	 * 删除账单详情
	 * @param TallyID
	 * @param TallyDetailID
	 */
	@RequestMapping("/to_StartAccountTallyDetialfromAccount")
	@ResponseBody
	public Info  deleteTallyDetialfromAccount(String TallyDetailID){
		 boolean flag = tallyService.accountTally(TallyDetailID);
	     return  flag ? new Info() : new Info("操作失败！");
	}
	
	/**
	 *修改账单状态
	 * @param TallyDetailID
	 */
	@RequestMapping("/to_changeTallyStatus")
	@ResponseBody
	public Info changeTallyStatus(String TallyDetailID){
		 boolean flag = tallyService.changeTallyAccountStatus(TallyDetailID);
	     return flag ? new Info() : new Info("操作失败！");
	}
	/**
	 * 跳转住院收费界面
	 * @return
	 */
	@RequestMapping("/to_LivePayTally")
	public String jumpToPayTally(){
		return "hspt_live_PayTally";
		
	}
	/**
	 * 查询需要缴费的账单
	 * @param page
	 * @param rows
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_queryCanPayTally")
	@ResponseBody
	public Map<String,Object> queryHasAccountNoPayTally(int page ,int rows,String liveID){
		return tallyService.queryHasNoPayAccountTallyByLiveID(page, rows, liveID);
	}
	/**
	 * 生成新的缴费单号
	 * @return
	 */
	@RequestMapping("/to_createNewPayId")
	@ResponseBody
	public String createNewPayId(){
		return tallyService.CreatePayID();
	}
	/**
	 * 新增缴费
	 * @param payTable
	 * @param LiveInID
	 * @param list
	 */
	@RequestMapping("/to_addNewPayTally")
	@ResponseBody
	public boolean addPayTally(PayVo payVo){
		return tallyService.addNewPayTally(payVo);
	}
	@RequestMapping("/to_hspt_live_feesQuery")
	public String tofeesQueryPage(){
		return "hspt_live_feesQuery";
	}
	@RequestMapping("/to_liveReport")
	public String liveINreport(){
		return "hspt_live_Report";
		
	}
	
	
	
	
	
	
	
	
}
